package algotithm.weekendrace.leetcode239.test1;

/**
 * @author 25068
 * @Date 2021/5/2 10:27
 * @Title 5746. 到目标元素的最小距离
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,2,3,4,5};
        int target = 5;
        int start = 3;
        int ans = solution.getMinDistance(nums,target,start);
        System.out.println(ans);
    }

    public int getMinDistance(int[] nums, int target, int start) {
        int ans = Integer.MAX_VALUE;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (nums[i] == target) {
                ans = Math.min(ans,Math.abs(i - start));
            }
        }
        return ans;
    }
}
